package 天梯赛.tts44.moni.a11;

import java.util.Scanner;

public class Main {
    static  int top=0;
    static   int a[];
    static  int b[];
    static   int n;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        a=new int[n];
        for (int i = 0; i < n; i++) {
            a[i]=sc.nextInt();
        }
        b=new int[n];
        dfs(0);
        for (int i = 0; i < n-1; i++) {
            System.out.print(b[i]+" ");
        }
        System.out.println(b[n-1]);
    }
    public  static  void  dfs(int x){
        if (x<n){
            //后序遍历  左右中的遍历方式
            dfs(x*2+1);
            dfs(x*2+2);
            //x是对应的下标  a[top]值是对应下标的值 后序遍历
            b[x]=a[top++];
        }
    }
}
